
/**
 * #info
 *
 * @author   lulinguo
 * @createTime   2018/06/13
 * @updateTime   2018/06/13
 * @description 模态框组件
 */

/**
 * #item
 *
 * @type aty-modal
 * @cn  模态框
 * @stPlugin true
 * @stContainer true
 * @mixins      [./components/components/popup/modal/modal.js]
 */

import Modal from './confirm'

function getModalInstance (render = undefined) {
  return Modal.newInstance({
    closable: true,
    maskClosable: false,
    footerHide: true,
    render: render
  })
}

function confirm (options) {
  const render = ('render' in options) ? options.render : undefined
  const instance = getModalInstance(render)
  instance.show(options)
  return instance
}

Modal.info = function (props = {}) {
  props.icon = 'info'
  props.showCancel = false
  return confirm(props)
}

Modal.success = function (props = {}) {
  props.icon = 'success'
  props.showCancel = false
  return confirm(props)
}

Modal.warning = function (props = {}) {
  props.icon = 'warning'
  props.showCancel = false
  return confirm(props)
}

Modal.error = function (props = {}) {
  props.icon = 'error'
  props.showCancel = false
  return confirm(props)
}

Modal.confirm = function (props = {}) {
  props.icon = 'confirm'
  props.showCancel = true
  return confirm(props)
}

Modal.remove = function () {
  if (!modalInstance) { // at loading status, remove after Cancel
    return false
  }

  const instance = getModalInstance()

  instance.remove()
}

export default Modal
